////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation.  All rights reserved.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// Portions Copyright (c) 2012 Kentaro Sekimoto  All rights reserved.
////////////////////////////////////////////////////////////////////////////

#include <tinyhal.h>
#include "..\FM4.h"
#include "FM4_I2C_driver.h"

#define DEF_I2C_CH	1

UINT32 i2c_ch = DEF_I2C_CH;

BOOL I2C_Internal_Initialize()
{
    BOOL flag = TRUE;
    flag |= FM4_I2C_Driver::Initialize(i2c_ch);
    return flag;
}

BOOL I2C_Internal_Uninitialize()
{
    BOOL flag = TRUE;
    flag |= FM4_I2C_Driver::Uninitialize(i2c_ch);
    return flag;
}

void I2C_Internal_XActionStart(I2C_HAL_XACTION* xAction, bool repeatedStart)
{
    FM4_I2C_Driver::MasterXAction_Start(i2c_ch, xAction, repeatedStart);
}

void I2C_Internal_XActionStop()
{
    FM4_I2C_Driver::MasterXAction_Stop(i2c_ch);
}

void I2C_Internal_GetClockRate(UINT32 rateKhz, UINT8& clockRate, UINT8& clockRate2)
{
    FM4_I2C_Driver::GetClockRate(i2c_ch, rateKhz, clockRate, clockRate2);
}

void I2C_Internal_GetPins(GPIO_PIN& scl, GPIO_PIN& sda)
{
    FM4_I2C_Driver::GetPins(i2c_ch, scl, sda);
}

void I2C_Internal_SetChannel(INT32 channel)
{
    i2c_ch = channel;
    //lcd_printf("I2C ch=%d\r\n", channel);
}
